package com.project.service.impl;

import com.project.bean.RoomBean;
import com.project.mapper.IRoomMapper;
import com.project.service.IRoomService;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RoomServiceImpl extends BaseService implements IRoomService {
    @Override
    public List<RoomBean> finAllRoom() {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        List<RoomBean> list =  mapper.finAllRoom();
        session.close();
        return list;
    }

    @Override
    public void updateStatue(int roomId, String status) {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        mapper.updateStatue(roomId,status);
        session.commit();
        session.close();
    }

    @Override
    public List<RoomBean> findByItem(String address, String state, String type, String repair) {
        Map map = new HashMap();
        map.put("address",address);
        map.put("state",state);
        map.put("type",type);
        map.put("repair",repair);

        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        List<RoomBean> list = mapper.findByItems(map);
        session.close();
        return list;
    }

    @Override
    public void addRoom(RoomBean room) {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        mapper.addRoom(room);
        session.commit();
        session.close();
    }

    @Override
    public void de(Integer roomId) {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        mapper.de(roomId);
        session.commit();
        session.close();
    }

    @Override
    public RoomBean findById(Integer roomId) {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        RoomBean room =  mapper.findById(roomId);
        session.close();
        return room;
    }
}
